﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SF.Common;
using System.Collections;
using System.Data;
using System.Configuration;
using SF.BLL;


namespace SF.Web.UI.mallCs
{
    public class detailed
    {
        public string loaddingUsing(Model.sf_user_info userInfo, string templateType)
        {
            string usingMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "syj")
                {
                    usingMsg = "<link rel='stylesheet' type='text/css' href='css/list.css' media='all' />";
                }
                else if (templateType == "weishanggreen")
                {
                    usingMsg = "<link rel='stylesheet' type='text/css' href='css/listgreen.css' media='all' />";
                }
            }
            return usingMsg;
        }
        public string loaddingJs(Model.sf_user_info userInfo, string templateType)
        {
            string jsMsg = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "syj")
                {
                    jsMsg = "function setAmounts(goodId, sizeId, colorId) {$.get('/tools/user_ajax.ashx', { action: 'get_amount_sizecolor', goodid: goodId, colorid: colorId, sizeid: sizeId }, function (res) {if (res.length > 0) {var temp = res.split('_');$('#lblGoodNum').text('剩余' + temp[0] + temp[1]);$('.number').attr('min', 1);$('.number').attr('max', temp[0]); $('#num').val(1);} else {$('#lblGoodNum').text('无库存');$('#num').attr('min', 0);$('#num').attr('max', 0);$('#num').val(0);}});}function checksize(obj) {var sizes = $('#sizeRight span').css('border', '2px solid rgb(228, 228, 228)');$('#sizeRight span').removeClass('check');$(obj).css('border', '2px red solid');$(obj).addClass('check');var sizeId = $(obj).attr('id');$('#hiddPDetailsizeId').val(sizeId);var colors = $('#colorRight span');for (var i = 0; i < colors.length; i++) {if ($(colors[i]).hasClass('check')) {var goodId = $('#hiddPDetailID').attr('value');var colorId = $(colors[i]).attr('id');setAmounts(goodId, sizeId, colorId);break;}}}function checkcolor(obj) {var colors = $('#colorRight span').css('border', '2px solid rgb(228, 228, 228)');$('#colorRight span').removeClass('check');$(obj).css('border', '2px red solid');$(obj).addClass('check');var colorId = $(obj).attr('id');$('#hiddPDetailcolorId').val(colorId);var sizes = $('#sizeRight span');for (var i = 0; i < sizes.length; i++) {if ($(sizes[i]).hasClass('check')) {var goodId = $('#hiddPDetailID').attr('value');var sizeId = $(sizes[i]).attr('id');setAmounts(goodId, sizeId, colorId);break;}}}  function addCard() {if (parseInt($('#num').attr('max')) < 1) {alert('请正确选择商品属性！');return;}$.get('/tools/user_ajax.ashx', { 'action': 'add_card', 'id': $('#hiddPDetailID').val(), 'num': $('#num').val(), 'sizeId': $('#hiddPDetailsizeId').val(), 'colorId':$('#hiddPDetailcolorId').val(), 'time': new Date().getTime() }, function (result) {if (result > 0) {$('#cartNum').text(parseInt($('#cartNum').text()) + 1);alert('成功添加到购物车！');} else if (result == '-1') {alert('购物车已添加过该商品！');} else if (result = '-2') {alert('请再次选择商品属性Test！');} else {alert('网络繁忙，请稍候再试');}});}$('.add').click(function () {var num = $('#num').val() * 1;if (parseInt($('#num').attr('max')) > num) {num = num + 1;$('#num').val(num);}});$('.reduce').click(function () {var num = $('#num').val() * 1;if (num > 1) {num = num - 1;}$('#num').val(num);});$('.add').mouseover(function () { $(this).css('cursor', 'pointer') }).mouseout(function () { $(this).css('cursor', 'default') });$('.reduce').mouseover(function () { $(this).css('cursor', 'pointer') }).mouseout(function () { $(this).css('cursor', 'default') });function buyGoods() {if (parseInt($('#num').val()) < 1) {alert('数量不能为0！');return;}if (parseInt($('#num').attr('max')) < 1) {alert('请先选择商品属性！');return;} $.get('/tools/user_ajax.ashx', { 'action': 'save_order', 'id': $('#hiddPDetailID').val(), 'num': $('#num').val(), 'sizeId': $('#hiddPDetailsizeId').val(), 'colorId': $('#hiddPDetailcolorId').val() }, function (result) {if (result != '') {location.href = '../mall/orderdetail.aspx?orderId=' + result;} else {alert('网络繁忙，请稍候再试');}});}function showProperty(sobj) {$('#detailTab span').removeClass('cur');$(sobj).addClass('cur');$('#productproperty').toggle();$('#p-detail').toggle();}";
                }
                else if (templateType == "weishanggreen")
                {
                    jsMsg = "function setAmounts(goodId, sizeId, colorId) {$.get('/tools/user_ajax.ashx', { action: 'get_amount_sizecolor', goodid: goodId, colorid: colorId, sizeid: sizeId }, function (res) {if (res.length > 0) {var temp = res.split('_');$('#lblGoodNum').text('剩余' + temp[0] + temp[1]);$('.number').attr('min', 1);$('.number').attr('max', temp[0]); $('#num').val(1);} else {$('#lblGoodNum').text('无库存');$('#num').attr('min', 0);$('#num').attr('max', 0);$('#num').val(0);}});}function checksize(obj) {var sizes = $('#sizeRight span').css('border', '2px solid rgb(228, 228, 228)');$('#sizeRight span').removeClass('check');$(obj).css('border', '2px rgba(85, 187, 117, 1) solid');$(obj).addClass('check');var sizeId = $(obj).attr('id');$('#hiddPDetailsizeId').val(sizeId);var colors = $('#colorRight span');for (var i = 0; i < colors.length; i++) {if ($(colors[i]).hasClass('check')) {var goodId = $('#hiddPDetailID').attr('value');var colorId = $(colors[i]).attr('id');setAmounts(goodId, sizeId, colorId);break;}}}function checkcolor(obj) {var colors = $('#colorRight span').css('border', '2px solid rgb(228, 228, 228)');$('#colorRight span').removeClass('check');$(obj).css('border', '2px rgba(85, 187, 117, 1) solid');$(obj).addClass('check');var colorId = $(obj).attr('id');$('#hiddPDetailcolorId').val(colorId);var sizes = $('#sizeRight span');for (var i = 0; i < sizes.length; i++) {if ($(sizes[i]).hasClass('check')) {var goodId = $('#hiddPDetailID').attr('value');var sizeId = $(sizes[i]).attr('id');setAmounts(goodId, sizeId, colorId);break;}}}  function addCard() {if (parseInt($('#num').attr('max')) < 1) {alert('请正确选择商品属性！');return;}$.get('/tools/user_ajax.ashx', { 'action': 'add_card', 'id': $('#hiddPDetailID').val(), 'num': $('#num').val(), 'sizeId': $('#hiddPDetailsizeId').val(), 'colorId':$('#hiddPDetailcolorId').val(), 'time': new Date().getTime() }, function (result) {if (result > 0) {$('#cartNum').text(parseInt($('#cartNum').text()) + 1);alert('成功添加到购物车！');} else if (result == '-1') {alert('购物车已添加过该商品！');} else if (result = '-2') {alert('请再次选择商品属性！');} else {alert('网络繁忙，请稍候再试');}});}$('.add').click(function () {var num = $('#num').val() * 1;if (parseInt($('#num').attr('max')) > num) {num = num + 1;$('#num').val(num);}});$('.reduce').click(function () {var num = $('#num').val() * 1;if (num > 1) {num = num - 1;}$('#num').val(num);});$('.add').mouseover(function () { $(this).css('cursor', 'pointer') }).mouseout(function () { $(this).css('cursor', 'default') });$('.reduce').mouseover(function () { $(this).css('cursor', 'pointer') }).mouseout(function () { $(this).css('cursor', 'default') });function buyGoods() {if (parseInt($('#num').val()) < 1) {alert('数量不能为0！');return;}if (parseInt($('#num').attr('max')) < 1) {alert('请先选择商品属性！');return;} $.get('/tools/user_ajax.ashx', { 'action': 'save_order', 'id': $('#hiddPDetailID').val(), 'num': $('#num').val(), 'sizeId': $('#hiddPDetailsizeId').val(), 'colorId': $('#hiddPDetailcolorId').val() }, function (result) {if (result != '') {location.href = '../mall/orderdetail.aspx?orderId=' + result;} else {alert('网络繁忙，请稍候再试');}});}function showProperty(sobj) {$('#detailTab span').removeClass('cur');$(sobj).addClass('cur');$('#productproperty').toggle();$('#p-detail').toggle();}";
                }
            }
            return jsMsg;
        }
        public string loaddingHtml(Model.sf_user_info userInfo, string goodId, string templateType)
        {
            string htmlMsg = "", appWhere = "";
            if (userInfo != null)
            {
                if (templateType == "weishangred" || templateType == "weishanggreen" || templateType == "syj")
                {
                    appWhere = Utils.getWhereByInfo(userInfo.busnieseNum, userInfo.appNum, userInfo.templatesNum);
                    string goodsParameters = "", goodDetailed = "", goodImg = "";
                    //sizeMsg="", colorMsg="";
                    BLL.bs_good_image imgBll = new BLL.bs_good_image();
                    BLL.bs_good_info goodBll = new BLL.bs_good_info();
                    BLL.bs_good_cart shopCartBll = new BLL.bs_good_cart();
                    //BLL.sf_goods_amounts amountBll = new BLL.sf_goods_amounts();
                    //BLL.sf_goods_size sizeBll = new BLL.sf_goods_size();
                    //BLL.sf_goods_color colorBll = new BLL.sf_goods_color();
                    Model.bs_good_info good = goodBll.GetModel(Convert.ToInt64(goodId));
                    string lblpriceTitle = "统一零售价：", lblGoodNum = "", lblOldPrice = "";
                    //if (good.goodsTypeNum.Equals("clothes") || good.goodsTypeNum.Equals("trousers") || good.goodsTypeNum.Equals("shoes"))
                    //{
                    //    lblpriceTitle = "惊爆价：";
                    //    lblGoodNum = "请选择尺码和颜色";
                    //    lblOldPrice = "￥" + good.showPrice;
                    //}
                    //List<Model.sf_goods_amounts> models = amountBll.GetModelList(" goodsNum='" + good.goodsNum + "' and " + appWhere + " order by sizeId,colorId ");
                    //if (models.Count > 0)
                    //{
                    //    //sizeMsg += "<li class='s-buy-li'><div class='left'>尺码：</div><div class='right' id='sizeRight'>";
                    //    //colorMsg += "<li class='s-buy-li'><div class='left'>颜色：</div><div class='right' id='colorRight'>";
                    //    //string sizeStr = "", colorStr = "";
                    //    foreach (Model.sf_goods_amounts amount in models)
                    //    {
                    //        Model.sf_goods_size size = sizeBll.GetModel(Convert.ToInt64(amount.sizeId));
                    //        Model.sf_goods_color color = colorBll.GetModel(Convert.ToInt64(amount.colorId));
                    //        if (size != null && color != null)
                    //        {
                    //            if (sizeStr.IndexOf(size.id.ToString() + "_") < 0)
                    //            {
                    //                sizeMsg += "<span class='size' id='" + size.id + "' title='" + size.sizeName + "' onclick='checksize(this);' >" + size.sizeName + "</span>";
                    //                sizeStr += size.id + "_";
                    //            }
                    //            if (colorStr.IndexOf(color.Id.ToString() + "_") < 0)
                    //            {
                    //                colorMsg += "<span class='size' id='" + color.Id + "' title='" + color.colorName + "' onclick='checkcolor(this);' >" + color.colorName + "</span>";
                    //                colorStr += color.Id + "_";
                    //            }
                    //        }
                    //    }
                    //    sizeMsg += "</div></li>";
                    //    colorMsg += "</div></li>";
                    //}
                    goodImg = "<img src='" + good.showImage + "' alt='" + good.name + "' height='174' width='290' />";

                    goodsParameters += "<li><label>名称</label><span>" + good.name + "</span></li>";
                    //goodsParameters += "<li><label>编号</label><span>" + good.goodsNum + "</span></li>";
                    //goodsParameters += "<li><label>类型</label><span>" + good.typeNum + "</span></li>";
                    //goodsParameters += "<li><label>品牌</label><span>" + good.brandName + "</span></li>";
                    //goodsParameters += "<li><label>产地</label><span>" + good.place + "</span></li>";
                    //goodsParameters += "<li><label>单位</label><span>" + good.unit + "</span></li>";
                    //goodsParameters += "<li><label>适合人群</label><span>" + good.suitPerson + "</span></li>";
                    //goodsParameters += "<li><label>上市年月</label><span>" + good.times + "</span></li>";
                    //goodsParameters += "<li><label>有效期</label><span>" + good.validTime + "</span></li>";

                    //Labix：剩下的商品信息从扩展字段获取
                    bs_good_extend goodExtendBll = new bs_good_extend();
                    var goodExtendList = goodExtendBll.GetModelList(string.Format("goodId='{0}'", goodId));
                    if (goodExtendList != null && goodExtendList.Any())
                    {
                        foreach (var goodExtend in goodExtendList)
                        {
                            goodsParameters += string.Format("<li><label>{0}</label><span>{1}</span></li>", goodExtend.fieldName, goodExtend.fieldValue);
                        }
                    }

                    //绑定商品介绍图片
                    good.goodImages = imgBll.GetModelList("goodId='" + good.id + "' and " + appWhere);
                    for (int i = 0; i < good.goodImages.Count; i++)
                    {
                        goodDetailed += "<img src='" + good.goodImages[i].imageUrl + "' alt='" + good.goodImages[i].remark + "' />";
                    }
                    //绑定购物车 数量
                    int min = 1, max = Convert.ToInt32(good.stock);
                    if (max == 0)
                    {
                        min = 0;
                        max = 0;
                    }
                    DataSet ds = shopCartBll.GetList("userId='" + userInfo.id + "' and " + appWhere);
                    htmlMsg = @"<body><div class='popup' id='popup' style='display: none;'></div>
<section class='head'><a href='javascript:void(0)' onclick='window.history.go(-1)' class='head_back'>上一页</a><h2>商品详情</h2>
<a href='cart.aspx' class='detail-cart'><i class='fa fa-shopping-cart'></i>(<span class='tips' id='cartNum'>" + ds.Tables[0].Rows.Count + @"</span>)</a></section><div class='mod_slider' id='loopImgDiv'>
<div class='inner'>" + goodImg + @"</div></div><div class='buy_area'><div id='testtt' style='display: none;'></div><div class='fn_wrap'>
<h1 class='fn' id='itemName'><label id='lblGoodName'>" + good.name + @"</label></h1></div><div class='price_wrap'>
<span class='tit' id='priceTitle'><label id='lblpriceTitle'>" + lblpriceTitle + @"</label></span>
<span class='price' id='price'>￥<label id='lblSalesPrice'>" + good.sellPrice.ToString() + @"</label></span>
<del class='old_price'><em id='priceMarket' style=''><label id='lblOldPrice'>" + lblOldPrice + @"</label></em></del>
<span class='flag' id='priceDis' style='display: none;'></span></div><div class='buy_tip' id='statusNotice' style='display: none;'>
<i class='icon_warn'></i><span id='statusNote'></span></div>
<div class='s-buy' id='skuCont'><ul class='s-buy-ul'><li class='s-buy-li'><div class='left'>数量：</div>
<div class='right'><span class='reduce' style='margin-left:10px;'>-</span>
<input class='number' name='quantity' autocomplete='off' value='1' min='" + min + @"' max='" + max + @"' id='num' readonly='true' />
<span class='add'>+</span><span class='annotation' id='Stock'><label id='lblGoodNum'>" + lblGoodNum + @"</label></span>
<input id='hiddPDetailID' name='name' value='" + goodId + @"' type='hidden' />
<input id='hiddPDetailsizeId' name='name' value='0' type='hidden' />
<input id='hiddPDetailcolorId' name='name' value='0' type='hidden' /></div></li></ul></div>
<div class='btn_wrap btn_wrap_static btn_wrap_nocart'>
<a class='btn btn_cart' id='btnCart' href='javascript:void(0);' onclick='addCard()'><i></i></a>
<a class='btn btn_buy' id='btnBuy' href='javascript:void(0);' onclick ='buyGoods()'>立即购买</a></div>    
</div><div class='mod_tab_wrap'><div class='mod_tab' id='detailTab'>
<span onclick='showProperty(this)' class='cur'>商品介绍</span>
<span class='' onclick='showProperty(this)'>商品参数</span></div></div>
<section class='p-a-c-list'><ul class='list-attribute' id='productproperty' style='display: none;'>" + goodsParameters + @"</ul></section>
<section style='display: block;' class='p-detail' id='p-detail'><div class='d-content' id='content'>" + goodDetailed + "</div></section></body>";
                }
            }
            return htmlMsg;
        }
    }
}
